<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/css/plat-style.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
    	<div class="layui-card-header">
   			<span class="layui-breadcrumb" lay-filter="breadcrumb">
              <a href="javascript:;">新闻中心</a>
              <a ><cite>编辑新闻</cite></a>
            </span>
   			<div class="layui-inline" style="float:right;">
				<button type="button" class="layui-btn layui-btn-sm"  onclick="history.go(-1);">返回列表</button>
            </div>
    	</div>
        <div class="layui-card-body" style="padding-top: 40px;">
            <form class="layui-form" id="newsAddForm" enctype="multipart/form-data">
                <input type="hidden" name="id" value="${news.id}">
                <%--<div class="layui-form-item">
                    <label class="layui-col-sm1 layui-col-sm-offset1"><span class="red">*&nbsp;</span>新闻类型</label>
                    <div class="layui-col-sm4">
                        <select name="type">
                            <option value="">请选择</option>
                            <option value="">请选择</option>
                            <option value="">请选择</option>
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>--%>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>新闻标题</label>
                    <div class="layui-input-inline">
                        <input type="text" name="title" autocomplete="off" class="layui-input" value="${news.title}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>新闻简介</label>
                    <div class="layui-input-inline">
                        <input type="text" name="descVal" autocomplete="off" class="layui-input" value="${news.descVal}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span class="red">*&nbsp;</span>封面图</label>
                    <div class="layui-input-block">
                        <label for="pcLogo" class="layui-btn layui-btn-sm layui-btn-primary">上传图片</label>
                        <input accept=".jpg,.png,.gif,.jpeg" type="file" style="display:none;" name="imgUrl" id="pcLogo"
                               onchange="showImg(this)"/>
                        <img id="pcImg" src="${news.url==""?' ':news.url}" width="200px" height="150px"/>
                    </div>
                </div>
                <div class="layui-form-item">
                	<label class="layui-form-label"><span class="red">*&nbsp;</span>新闻内容</label>
                    <div class="layui-input-block">
                        <textarea id="content" name="content" style="display: none">${news.content}</textarea>
                        <script id="articleEditor" type="text/plain" style="width:100%;height:400px;"></script>
                    </div>
                </div>
            </form>
            <div class="layui-form-item" style="text-align:center">
                <div class="layui-input-block">
                    <div class="layui-footer" style="left: 0;">
                        <button class="layui-btn" onclick="saveNews()">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript" src="/js/plugins/image/previewImg.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form','layedit'], function(){
        var $ = layui.$,layer = layui.layer;
    });


    $(function () {
        var ue = UE.getEditor('articleEditor');
        UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
        UE.Editor.prototype.getActionUrl = function(action) {
            if (action == '/uploadFile') {
                return '/base/uploadRichFile';
            } else {
                return this._bkGetActionUrl.call(this, action);
            }
        };
        UE.getEditor('articleEditor').ready(function() {
            UE.getEditor('articleEditor').setContent($("#content").text());
        })
    });

    function saveNews(){
    	$("#content").val(UE.getEditor('articleEditor').getContent());
        $("#newsAddForm").ajaxSubmit({
            type: 'post',
            url: "/news/doEditNews",
            data: $("#newsAddForm").serialize(),
            dataType: 'json',
            success: function (data) {
                if (data.status) {
                    layer.msg(data.desc);
                    setTimeout(function () {
                        window.location.href = "/news/news";
                    }, 1000)
                } else {
                    layer.msg(data.desc);
                }
            },
            error: function () {
                layer.msg("请检查页面信息是否正确");
            }
        });
    }
</script>
</body>
</html>